package com.acme.mock;

import java.util.ArrayList;

public class BankService {

	AccountFactory accountFactory;
	ClientFactory clientFactory;

	public BankService() {
		this.accountFactory = new AccountFactory();
		this.clientFactory = new ClientFactory();
	}

	public String addClient(String accType, double balance, double overdraft,
			String name, String g, Bank bank) {
		StringBuilder answer = new StringBuilder();
		Account account = accountFactory
				.getAccount(accType, balance, overdraft);
		Client client = clientFactory.getClient(account, name, g);
		System.out.println(client);
		ArrayList<Client> clients = bank.getClients();
		for (Client cl : clients) {
			if (cl.getName().equals(name)) {
				answer.append("Client with the name ").append(name)
						.append(" already exists");
				return answer.toString();
			}
		}
		clients.add(client);
		answer.append("Client ").append(name).append(" has been added");
		return answer.toString();
	}
	
	public String deleteClient(String name, Bank bank) {
		ArrayList<Client> clients = bank.getClients();
		for(Client client: clients)
			if(client.getName().equals(name)) {
				clients.remove(client);
				return "Client " + name + "has been deleted";
			}
		return "Client " + name + "does not exist";
	}

}
